<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>FLDCMS后台管理系统</title>
<meta name="keywords" content="FLDCMS，FLDCMS后台管理系统">
<meta name="description" content="FLDCMS，是一款由FLD开发的轻量级扁平化网站后台模板，适合中小型CMS后台系统。">
{include file="public/header" /}
<style>
	img[nc_type="flex"]{cursor:pointer;}
</style>
</head>
<body>
<article class="page-container">
	<form action="{:url('role/edit')}" method="post" class="form form-horizontal" id="form-edit">
		<input type="hidden" name="form_submit" value="ok"/>
		<input type="hidden" name="role_id" id="role_id" value="{$vo.role_id}"/>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$vo.role_name}" placeholder="请填写角色名称" id="role_name" name="role_name">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">角色描述：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$vo.role_remark}" placeholder="请填写角色描述" id="role_remark" name="role_remark">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">角色权限：</label>
			<div class="formControls col-xs-8 col-sm-9">
				{notempty name="node_list"}
				{foreach name="node_list" item="nvo"}
				<dl class="permission-list">
					<dt>
						<label>
							<input type="checkbox" value="{$nvo.node_id}" name="role_access[]"
								 {containstr name="node_info" value="$nvo.node_id"}checked="checked"{/containstr}
							>&nbsp;{$nvo.node_title}
						</label>
					</dt>
					<dd>
						{notempty name="nvo.c_list"}
						{foreach name="nvo.c_list" item="cvo"}
						<dl class="cl permission-list2">
							<dt>
								<label class="">
									<input type="checkbox" value="{$cvo.node_id}" name="role_access[]"
										{containstr name="node_info" value="$cvo.node_id"}checked="checked"{/containstr}
									>&nbsp;{$cvo.node_title}
								</label>
							</dt>
							{notempty name="cvo.c_list"}
							<dd>
								{foreach name="cvo.c_list" item="tvo"}
								<label class="">
									<input type="checkbox" value="{$tvo.node_id}" name="role_access[]"
										{containstr name="node_info" value="$tvo.node_id"}checked="checked"{/containstr}
									>&nbsp;{$tvo.node_title}
								</label>
								{/foreach}
							</dd>
							{/notempty}
						</dl>
						{/foreach}
						{/notempty}
					</dd>
				</dl>
				{/foreach}
				{/notempty}
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button class="btn btn-secondary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
			</div>
		</div>
	</form>
</article>
{include file="public/footer" /}
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$(".permission-list dt input:checkbox").click(function(){
		$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
	});
	$(".permission-list2 dd input:checkbox").click(function(){
		var l =$(this).parent().parent().find("input:checked").length;
		var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
		if($(this).prop("checked")){
			$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
		}
		else{
			if(l==0){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
			}
			if(l2==0){
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
			}
		}
	});
	
	$("#form-edit").validate({
		rules:{
			role_name:{
				required:true,
				maxlength:20,
				remote: {
				    url: "{:url('role/checkEdit_ajax')}",    //后台处理程序
				    type: "post",               //数据发送方式
				    dataType: "json",           //接受数据格式   
				    data: {                     //要传递的数据
				    	role_name : function() {
				            return $("#role_name").val();
				        },
				        role_id : function(){
				        	return $('#role_id').val();
				        }
				    }
				}
			},
		},
		messages: {
			role_name:{
				required:'角色名称不能为空',
				maxlength:'角色名称不能大于20个字符',
				remote: '角色名称已经存在',
			},
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
                dataType:"json",
                success:function(data){
                   if(data.error == 0){
                	   	layer.msg(data.msg, {icon: 1,time: 1000}, function(){
                	   		var index = parent.layer.getFrameIndex(window.name);
                			parent.location.reload();
               				parent.layer.close(index);
                		});
                   }else{
                	   layer.msg(data.msg,{icon:2,time:1000});
                   }
                }
            });
		}
	});
});

</script>
</body>
</html>